
import { createSlice } from '@reduxjs/toolkit';

// 初始状态
const initState = {
  count: 1
}

// 创建redux切片对象
export const setInitState = createSlice({
  name: "appState", // 切片名称 用来标识redux
  initialState: initState, // 需要管理的状态
  reducers: {  // 配置reducer 用以更新的状态
    countAdd (state) {
      state.count++;
    },
    setCount (state, action) {
      state.count = action.payload;
    }
  }
})

// 导出状态
export const { countAdd, setCount } = setInitState.actions;
// 导出reducer
export const SetInitState = setInitState.reducer;